<template>
  <div class="apply-container">
    <div class="apply-top">
      <div class="apply-search"></div>
      <div class="apply-btn"><el-button type="primary" size="small" @click="isShowDialog = true">新增</el-button></div>
    </div>
    <el-scrollbar style="height: calc(100vh - 160px)" class="scrollbar" id="scroll-bar">
      <el-table :data="list">
        <el-table-column label="艺术家名" prop="art_name"></el-table-column>
        <el-table-column label="视频详情" prop="video_detail"></el-table-column>

        <el-table-column label="封面图">
          <template slot-scope="scope">
            <el-image
              v-if="scope.row.video_page"
              style="width: 100px; height: 40px"
              :src="scope.row.video_page"
              :preview-src-list="[scope.row.video_page]"
              fit="cover"
            ></el-image>
            <span v-else>暂无图片</span>
          </template>
        </el-table-column>
        <el-table-column label="视频地址" prop="video_path">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" :content="scope.row.video_path" placement="top-start">
              <div>
                {{ scope.row.video_path }}
              </div>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column label="视频简介" prop="video_comment"></el-table-column>

        <el-table-column label="上传时间" prop="upload_time"></el-table-column>
        <el-table-column label="申请状态" prop="is_audit">
          <template slot-scope="scope">
            {{ getStatusName(scope.row.is_audit) }}
          </template>
        </el-table-column>

        <el-table-column label="最后修改时间" width="160" prop="data_update_time"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope" v-if="scope.row.is_audit === 0">
            <el-button type="primary" @click="passApply(scope.row.data_id)" size="mini">通过</el-button>
            <!-- <el-button type="danger" @click="refuseApply(scope.row.data_id, scope.row.name)" size="mini">
              拒绝
            </el-button> -->
          </template>
        </el-table-column>
      </el-table>
    </el-scrollbar>
    <paging ref="page" :func="getList"></paging>

    <el-dialog @closed="onClose" :title="'拒绝' + apply_name + '的申请'" :visible.sync="isShowDialog">
      <el-form :model="dataParams" :rules="rules" ref="dataParams" label-width="80px" class="demo-dataParams">
        <el-form-item label="拒绝理由" prop="message">
          <el-input v-model="dataParams.message"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isShowDialog = false">取 消</el-button>
        <el-button type="primary" @click="dialogConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import paging from '@/components/paging';
  import auditManage from '@/api/video';
  export default {
    name: 'audit-view',
    components: {
      paging,
    },
    data() {
      return {
        list: [],
        isShowDialog: false,
        apply_id: '',
        apply_name: '',
        dataParams: { message: '', op: 'apply_fail' },
        rules: {
          message: [{ required: true, message: '拒绝理由', trigger: 'blur' }],
        },
      };
    },
    async mounted() {
      this.refresh();
    },
    methods: {
      refresh() {
        this.$refs.page.refresh();
      },
      search() {
        this.$refs.page.search();
      },
      async getList(callback) {
        let res = await auditManage.getVideoAudit();
        this.list = res.item_list;
        callback(this.list, res.total_count);
      },
      getStatusName(is_audit) {
        if (is_audit === 0) {
          return '申请中';
        } else if (is_audit === 1) {
          return '授权完成';
        } else {
          return '拒绝申请';
        }
      },
      async passApply(data_id) {
        await auditManage.updVideoAudit(data_id, { is_audit: 1 });
        this.getList();
      },
      async refuseApply(data_id, name) {
        this.apply_id = data_id;
        this.apply_name = name;
        this.isShowDialog = true;
      },
      async dialogConfirm() {
        this.$refs.dataParams.validate(async (valid) => {
          if (valid) {
            await auditManage.updVideoAudit(this.apply_id, this.dataParams);
            this.getList();
            this.isShowDialog = false;
            this.apply_id = '';
            this.apply_name = '';
            this.dataParams = { message: '', op: 'apply_fail' };
          }
        });
      },
      onClose() {
        this.apply_id = '';
        this.apply_name = '';
        this.dataParams = { message: '', op: 'apply_fail' };
      },
    },
  };
</script>

<style lang="less" scoped>
  .apply-container {
    height: 100%;
    .apply-top {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 12px;
      .apply-search {
        display: flex;
      }
    }
    .apply-list {
      display: flex;
      flex-flow: row wrap;
      width: 100%;
      height: 100%;
      .apply-item {
        width: calc(50% - 6px);
        height: 100px;
        display: flex;
        margin-bottom: 6px;
        border: 1px solid #f3f3f3;
        .item-content {
          margin: 10px;
          p {
            line-height: 40px;
          }
        }
      }
    }
  }
</style>
